<?php
	
class HitsController extends AppController
{
	var $name = "Hits";
	var $components = array('Cookie');
	//generates a image and add a counter
	//right now only to be used for site counter not for page specific counrter.
	function addHit()
	{
		$cookieKey = "sitehit";
		if($this->Cookie->read($cookieKey) == false)
		{
			$referer = $this->referer();
			$this->Hit->addHit($referer);
			$this->Cookie->write($cookieKey,'visited',true,'+1 hour');
				
		}else
		{

		}
		header("Content-type:image/png");
		if(function_exists('imagecreate'))
		{
			$im = imagecreate(1,1);
			imagejpeg($im);
			imagedestroy($im);
		}else
		{

		}
		$this->_stop();
	}
	
	function admin_summary()
	{
		Configure::write('debug', 0);
		$this->layout = 'ajax';
		
		if(!isInstalled('reporting'))
		{
			echo __("Reporting engine not found!");
			exit;
		}
		$this->set('hits', $this->Hit->getLastXDays(30));
	}
}
?>